package com.woniuxy.java106crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.java106crm.entity.Product;
import com.woniuxy.java106crm.mapper.BasicDataMapper;
import com.woniuxy.java106crm.request.ResPage;
import com.woniuxy.java106crm.service.BasicDataService;
import com.woniuxy.java106crm.vo.FindProductVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BasicDataServiceImpl implements BasicDataService {
    //注入mapper对象
    @Resource
    private BasicDataMapper basicDataMapper;

    @Override
    public ResPage<List<Product>> findProductByName(FindProductVo findProductVo) {
        //1.实现分页逻辑
        PageHelper.startPage(findProductVo.getPage(), findProductVo.getSize());
        List<Product> products = basicDataMapper.findProductByName(findProductVo.getName().trim());
        //2.获取分页的信息
        PageInfo<Product> pf = new PageInfo<>(products);
        return new ResPage<>(pf.getPageNum(),pf.getSize(),pf.getTotal(),pf.getPages(),pf.getList());
    }


}
